package com.设计模式.代理模式.动态代理.CGLIB动态代理;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @author: LCG
 * 作者: LCG
 * 日期: 2021/3/1  14:14
 * 描述:
 */
public class MyMethodInterceptor2<T> implements MethodInterceptor {


    private Enhancer enhancer=new Enhancer();

    public T getInstance(Class<T> tClass){
        enhancer.setSuperclass(tClass);
        enhancer.setCallback(this);
        return (T)enhancer.create();
    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {


        System.out.println("========test02的实现=======");

        return "test02";
    }

}
